/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package commonClasses.Messages;

import commonClasses.*;
import commonClasses.commonInterfaces.ItemIntf;
import commonClasses.commonInterfaces.MsgIntf;
import commonClasses.commonInterfaces.ProtocolIntf;

/**
 *
 * @author Pozytywny!
 */
public class NewBidMsg extends Msg implements MsgIntf {

    private ItemIntf _item = null;

    public NewBidMsg(ProtocolIntf protocol, ItemIntf item) {
        super(protocol, MagicNumbers.NEW_BID_MSG_NR);
        _item = item;
    }

    public NewBidMsg(ProtocolIntf protocol) {
        super(protocol, MagicNumbers.NEW_BID_MSG_NR);

    }

    public ItemIntf getItem() {
        return _item;
    }

    public void receive() {
        long itemID = receiveUint();
        Utils.clientReceived(itemID);

        long priceValue = receiveUint();
        Utils.clientReceived(priceValue);

        String priceCurrency = String.valueOf(receiveCharArr(
                MagicNumbers.CURRENCY_STRING_LENGTH));
        Utils.clientReceived(priceCurrency);

        int length = longToInt(receiveUint());
        Utils.clientReceived(length);


        this._item = new Item();
        _item.setBasic(itemID, new Price(priceCurrency, priceValue), null);

    }

    public void send() throws Exception {


        int mesgId[] = this.idToIntArr();
        sendIntArr(mesgId);

        int itemId[] = longToArr(_item.getId());
        sendIntArr(itemId);

        int priceValue[] = longToArr(_item.getPrice().getValue());
        sendIntArr(priceValue);

        char priceCurrent[] = stringToCharArr(_item.getPrice().getCurrent());
        sendCharArr(priceCurrent);

        int length[] = longToArr(0);
        sendIntArr(length);
        //a desc nie wysylamy!.



    }
}
